﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FileBrowserDemo.aspx.cs" Inherits="FileBrowser" %>
<%@ Import Namespace="System.IO" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>

    <script type="text/javascript">
        function SelectFile(file)
        {
 	        window.top.opener.SetUrl( encodeURI( file ) ) ;
	        window.top.close() ;
	        window.top.opener.focus() ;
         }
         
         function Show(display)
         {
            switch(display)
            {
                case "List":
                    document.getElementById("FileList").style.display="block";
                    document.getElementById("FileIcon").style.display="none";
                    document.getElementById("FileDetails").style.display="none";
                break;
                case "Icon":
                    document.getElementById("FileList").style.display="none";
                    document.getElementById("FileIcon").style.display="block";
                    document.getElementById("FileDetails").style.display="none";
                break;
                default:
                    document.getElementById("FileList").style.display="none";
                    document.getElementById("FileIcon").style.display="none";
                    document.getElementById("FileDetails").style.display="block";
                break;
            }
         }

    </script>

</head>
<body onload="Show('FileDetails');">
    <form id="form1" runat="server">
        <div>
            <table style="width: 100%;">
                <tr>
                    <td colspan="2">
                        <asp:Panel ID="Panel1" runat="server"　ScrollBars="Vertical" Width="100%">
                            <asp:DataList ID="FileList" runat="server">
                                <ItemTemplate>
                                    <asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"Name") %>'></asp:Label>
                                    <asp:HyperLink ID="HyperLink1" runat="server" onclick='<%# DataBinder.Eval(Container.DataItem,"Name","SelectFile(\"{0}\");") %>'>选择</asp:HyperLink>
                                </ItemTemplate>
                            </asp:DataList>
                            <asp:GridView ID="FileDetails" runat="server" Width = "100%" AutoGenerateColumns="False">
                                <Columns>
                                    <asp:TemplateField HeaderText="文件名">
                                        <ItemTemplate>
                                            <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# string.Format("javascript:SelectFile(\"{0}\");",GetUrl((FileInfo)Container.DataItem)) %>'
                                                Text='<%# Eval("Name") %>'></asp:HyperLink>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:BoundField DataField="Length" HeaderText="大小" ReadOnly="True" />
                                    <asp:BoundField DataField="LastWriteTime" DataFormatString="{0:d}" HeaderText="日期"
                                        HtmlEncode="False" ReadOnly="True" />
                                </Columns>
                            </asp:GridView>
                            <asp:DataList ID="FileIcon" runat="server">
                            </asp:DataList>
                        </asp:Panel>
                    </td>
                </tr>
                <tr height="24px" width="100%">
                    <td style="width: 185px" >
                        &nbsp;<img alt="详细" src="" onclick="Show('Details');" />
                        <img alt="列表" src="" onclick="Show('List');" />
                        <img alt="图标" src="" onclick="Show('Icon');" /></td>
                    <td >
                        &nbsp; &nbsp;
                        <asp:FileUpload ID="FileUpload1" runat="server" Width="321px" />
                        <asp:Button ID="UploadButton" runat="server" Text="上传" Width="57px" OnClick="UploadButton_Click" /></td>
                </tr>
            </table>
        </div>
    </form>
</body>
</html>
